<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="ui/css/mui.min.css" rel="stylesheet" type="text/css" />
<link href="style/style.css" rel="stylesheet" type="text/css" />
<script src="ui/js/mui.min.js"></script>
<script src="js/jquery-2.1.4.min.js"></script>
</head>
<body>
<div id="sidedrawer" class="mui--no-user-select">
	<div id="sidedrawer-brand" class="mui--appbar-line-height mui--text-title">ThinServer</div>
	<div class="mui-divider"></div>
	<ul>
	  <li>
		<strong>ThinServer</strong>
		<ul>
		  <li><a href="http://git.oschina.net/sanluan/ThinServer" target="blank">GIT源码托管</a></li>
		</ul>
	  </li>
	  <li>
		<strong>PublicCMS</strong>
		<ul>
		  <li><a href="http://www.publiccms.com/" target="blank">主页</a></li>
		  <li><a href="http://git.oschina.net/sanluan/PublicCMS" target="blank">GIT源码托管</a></li>
		  <li><a href="http://shang.qq.com/wpa/qunwpa?idkey=8a633f84fb2475068182d3c447319977faca6a14dc3acf8017a160d65962a175" target="blank">QQ群</a></li>
		</ul>
	  </li>
	</ul>
</div>
<header id="header">
  <div class="mui-appbar mui--appbar-line-height">
    <div class="mui-container-fluid">
      <a class="sidedrawer-toggle mui--visible-xs-inline-block js-show-sidedrawer">☰</a>
      <a class="sidedrawer-toggle mui--hidden-xs js-hide-sidedrawer">☰</a>
      <span class="mui--text-title mui--visible-xs-inline-block">ThinServer</span>
    </div>
  </div>
</header>
<div id="content-wrapper">
	<div class="mui--appbar-height"></div>
	<div class="mui-container-fluid">
	  <br>
	  <h1>已部署应用</h1>
	  <div class="mui-panel">
<#if handlerMap??>
	<#list handlerMap?keys>
		<ul class="mui-tabs__bar">
		<#items as k>
			<li<#if k?is_first> class="mui--is-active"</#if>><a data-mui-toggle="tab" class="mui-btn--raised" data-mui-controls="pane-justified-${k?index}">${k}</a></li>
		</#items>
			<li<#if handlerMap?keys?size lt 1> class="mui--is-active"</#if>><a data-mui-toggle="tab" class="mui-btn--raised" data-mui-controls="pane-justified-${handlerMap?keys?size}">+</a></li>
		</ul>
	</#list>
	<#list handlerMap?keys as k>
		<div class="mui-tabs__pane<#if k?is_first> mui--is-active</#if>" id="pane-justified-${k?index}">
			<h2>应用路径：${handlerMap[k].webappPath}<#if 'ROOT'!=k> <a href="${k}/" target="_blank">访问</a></#if></h2>
			<#if 'ROOT'!=k>
				<a href="manager/unload/${k}" class="mui-btn mui-btn--primary">卸载</a>
			</#if>
			<a href="manager/reload/${k}" class="mui-btn mui-btn--primary">重新加载</a>
		</div>
	</#list>
		<div class="mui-tabs__pane<#if handlerMap?keys?size lt 1> mui--is-active</#if>" id="pane-justified-${handlerMap?keys?size}">
			<h2>添加新应用</h2>
			<div class="mui-form--inline">
			  <div class="mui-textfield mui-textfield--float-label">
				<input type="text" name="path" required>
				<label>路径(无需填写webapps/)</label>
			  </div>
			  <div class="mui-textfield mui-textfield--float-label" id="fullPath" style="display:none">
				<input type="text" name="fullpath">
				<label>应用所在目录</label>
			  </div>
			  <a class="mui-btn mui-btn--primary" id="createApp" href="manager/load/">加载</a>
			</div>
			<div class="mui-checkbox">
				<label>
				  <input type="checkbox" name="isFullPath" onclick="if($(this).is(':checked')){$('#fullPath').show();}else{$('#fullPath').hide();}">
				  不在webapps目录下
				</label>
			</div>
		</div>
<#else>
		<p>本应用未得到管理授权</p>
</#if>
	  </div>
	</div>
</div>
<footer id="footer">
  <div class="mui-container-fluid">
    <br>${.now}
  </div>
</footer>
<script>
jQuery(function($) {
	var $bodyEl = $('body'),
	$sidedrawerEl = $('#sidedrawer');
	function showSidedrawer() {
	// show overlay
	var options = {
	  onclose: function() {
		$sidedrawerEl
		  .removeClass('active')
		  .appendTo(document.body);
	  }
	};
	var $overlayEl = $(mui.overlay('on', options));
	// show element
	$sidedrawerEl.appendTo($overlayEl);
	setTimeout(function() {
	  $sidedrawerEl.addClass('active');
	}, 20);
	}
	function hideSidedrawer() {
		$bodyEl.toggleClass('hide-sidedrawer');
	}
	$('.js-show-sidedrawer').on('click', showSidedrawer);
	$('.js-hide-sidedrawer').on('click', hideSidedrawer);
	var $titleEls = $('strong', $sidedrawerEl);
	$titleEls.on('click', function() {
	  $(this).next().slideToggle(200);
	});
	$('.mui-btn').click(function(){
		$.getJSON($(this).attr('href'), function(data){
			if(data.result) {
				location.reload(true);
			}
		});
		return false;
	});
	$('#createApp').click(function(){
		var url=$(this).attr('href');
		url+=$('input[name=path]').val();
		if($('input[name=isFullPath]').is(':checked')&&$('input[name=fullpath]').val()){
			url+='/'+$('input[name=fullpath]').val();
		}
		$.getJSON(url, function(data){
			if(data.result) {
				location.reload(true);
			}
		});
		return false;
	});
});
</script>
</body>
</html>
